import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:rabbit_mobile/view/goods_details/models/goods_details_model.dart';
import 'package:rabbit_mobile/widget/custom_cache_image_widget/index.dart';

class GoodsDetailsEvaluation extends StatefulWidget {
  final GoodsDetailsEvaluationInfoModel evaluation;
  const GoodsDetailsEvaluation({super.key, required this.evaluation});

  @override
  State<GoodsDetailsEvaluation> createState() => _GoodsDetailsEvaluationState();
}

class _GoodsDetailsEvaluationState extends State<GoodsDetailsEvaluation> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 12),
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      width: double.infinity,
      decoration: const BoxDecoration(color: Colors.white),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                padding: const EdgeInsets.only(left: 12),
                decoration: const BoxDecoration(
                  border: Border(
                    left: BorderSide(
                      width: 3,
                      color: Color(0xFF00CE8A),
                    ),
                  ),
                ),
                child: const Text("評價", style: TextStyle(fontSize: 16, color: Colors.black)),
              ),
              const SizedBox(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("更多評價", style: TextStyle(fontSize: 14, color: Colors.grey)),
                    Icon(Icons.chevron_right_outlined, color: Colors.grey)
                  ],
                ),
              )
            ],
          ),
          Container(
            margin: const EdgeInsets.symmetric(vertical: 8),
            height: .6,
            decoration: const BoxDecoration(color: Color.fromARGB(62, 158, 158, 158)),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    margin: const EdgeInsets.only(right: 10),
                    child: ClipOval(
                      child: CustomCacheImageWidget(
                        imageUrl: widget.evaluation.member.avatar,
                        width: 30,
                        height: 30,
                        fit: BoxFit.cover,
                        // errorBuilder: (_, __, ___) {
                        //   return const Icon(Icons.error);
                        // },
                      ),
                    ),
                  ),
                  Expanded(
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              widget.evaluation.member.account,
                              style: const TextStyle(fontSize: 14, color: Colors.grey),
                            ),
                            Wrap(
                              spacing: 2, // 每个子项的间距
                              children: List.generate(5, (index) {
                                return Image.asset(
                                  'assets/2.0x/star_comment.png',
                                  width: 20,
                                  height: 20,
                                );
                              }),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.only(top: 9, left: 40),
                child: Text(
                  widget.evaluation.content,
                  style: const TextStyle(fontSize: 14, color: Colors.grey),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 9, left: 40),
                child: Wrap(
                  spacing: 6,
                  children: List.generate(widget.evaluation.pictures.length, (index) {
                    return CustomCacheImageWidget(
                      imageUrl: widget.evaluation.pictures[index],
                      width: 70,
                      height: 70,
                    );
                  }),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 9, left: 40),
                child: Row(
                  children: [
                    Text("購買時間: ${widget.evaluation.orderInfo.createTime}",
                        style: const TextStyle(fontSize: 14, color: Colors.grey)),
                    RichText(
                      text: TextSpan(
                        children: List.generate(
                          widget.evaluation.orderInfo.specs.length,
                          (index) {
                            return TextSpan(
                              text: widget.evaluation.orderInfo.specs[index].valueName,
                              style: const TextStyle(fontSize: 14, color: Colors.grey),
                            );
                          },
                        ),
                      ),
                    )
                  ],
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
